package cn.tedu.project.oa.attendanceRule.controller;

import cn.tedu.project.oa.attendanceRule.pojo.entity.OvertimeRule;
import cn.tedu.project.oa.attendanceRule.service.IOvertimeRuleService;
import cn.tedu.project.oa.base.response.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/oa/attendance/overtime")
@Api(tags = "09.加班规则")
public class OvertimeRuleController {
    @Autowired
    private IOvertimeRuleService overtimeRuleService;

    /**
     * 查询加班规则列表
     */
    @GetMapping("/list")
    public JsonResult list(OvertimeRule overtimeRule)
    {

        List<OvertimeRule> list = overtimeRuleService.selectOvertimeRuleList(overtimeRule);
        return JsonResult.ok(list);
    }

//    /**
//     * 导出加班规则列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:rule:export')")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, OvertimeRule overtimeRule)
//    {
//        List<OvertimeRule> list = overtimeRuleService.selectOvertimeRuleList(overtimeRule);
//        ExcelUtil<OvertimeRule> util = new ExcelUtil<OvertimeRule>(OvertimeRule.class);
//        util.exportExcel(response, list, "加班规则数据");
//    }

    /**
     * 获取加班规则详细信息
     */
    @GetMapping(value = "/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id)
    {
        return JsonResult.ok(overtimeRuleService.selectOvertimeRuleById(id));
    }

    /**
     * 新增加班规则
     */
    @PostMapping
    public JsonResult add( OvertimeRule overtimeRule)
    {
        return JsonResult.ok(overtimeRuleService.insertOvertimeRule(overtimeRule));
    }

    /**
     * 修改加班规则
     */
    @PutMapping
    public JsonResult edit( OvertimeRule overtimeRule)
    {
        return JsonResult.ok(overtimeRuleService.updateOvertimeRule(overtimeRule));
    }

    /**
     * 删除加班规则
     */
    @DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids)
    {
        return JsonResult.ok(overtimeRuleService.deleteOvertimeRuleByIds(ids));
    }
}
